<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ChannelRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'one_channel' => 'required',
            'pid' => 'required',
            'name' => 'required|max:50',
        ];
    }

    public function messages()
    {
        $isOneChannel = request()->get('is_one_channel','');
        $isTwoChannel = request()->get('is_two_channel','');
        $message = [
            'name.required' => '请输入渠道名称',
            'name.max'      => '渠道名称最多输入50个字符',
            'pid.required'  => '请输入所属父渠道',
            'one_channel.required' => '请输入一级渠道',
        ];
        if ($isOneChannel){
            $message['name.max'] = '输入的一级渠道过长，请重新输入';
        }
        if ($isTwoChannel){
            $message['name.max'] = '输入的二级渠道过长，请重新输入';
        }
        return $message;
    }
}
